package com.atguigu.gulimall.member.service.impl;
//JSONObject操作
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

public class JsonOper {

    public static void main(String[] args) {
        String json1 ="[\n" +
                "{\n" +
                "\"id\":1,\n" +
                "\"type\":\"text\",\n" +
                "\"style\":{\n" +
                " \"color\":\"#1111\",\n" +
                " \"zIndex\":2\n" +
                " }\n" +
                "},\n" +
                "{\n" +
                "\"id\":2,\n" +
                "\"type\":\"text\",\n" +
                "\"style\":{\n" +
                " \"color\":\"#B24\"\n" +
                " }\n" +
                "}\n" +
                "]";

        JSONArray jsonArray =JSONArray.parseArray(json1);
        for(int i=0;i<jsonArray.size();i++) {
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            jsonObject.put("type", "int");
            JSONObject style = (JSONObject)jsonObject.get("style");
            if(i==0){
                style.put("color", "#FFFFFF");
                style.remove("zIndex");
            }
            if(i==1){
                style.put("color", "#111111");
            }
        }
        System.out.println(jsonArray);

        /* JSONObject jsonObject = jsonArray.getJSONObject();
        System.out.println(jsonObject.get("style"));

        jsonObject.put("style", "高磊");*/

//        JSONObject[] dataZoom = new JSONObject[]{JSONObject.parseObject("{\"type\":\"slider\",\"show\":\"true\",\"start\":1,\"end\":100}")};
//        JSONObject[] dataZoom2 = new JSONObject[]{JSONObject.parseObject(json)};
      //  JSONObject jsonObject = JSON.parseObject(json);
    //    String name = jsonObject.getString("id");
//        String gender = jsonObject.getString("gender");
//        String header = jsonObject.getString("profile_image_url");

    }
}
